/*
 * nwk.h
 *
 *  Created on: Jun 9, 2013
 *      Author: Jonathan
 */

#ifndef NWK_H_
#define NWK_H_

#include "nrf24.h"

/* ----====**** MACROS ****====---- */

/* ----====**** DEFINES ****====---- */
#define BROADCAST_ADDRESS	0xC2C2C2C2FFUL
#define NWK_QUEUE_SIZE		8	/* number of packets(+1) allowed on the outgoing queue */

/* ----====**** TYPE DEFINITIONS ****====---- */
//TODO2: add retries to the nwk_packet_t NOTE: then it may make sense to have a RX packet_t separate from a TX packet_t
typedef struct nwk_packet_type
{
	uint8_t dest_address[NRF24_ADDR_LEN];
	uint8_t data[32];
	uint8_t data_len;
}nwk_packet_t;

typedef enum e_nwk_return_t
{
	NWK_SUCCESS 			= 0,	// 0
	NWK_FAILURE,
	NWK_BAD_ADDRESS,
	NWK_BAD_DATA_PTR,
	NWK_BAD_DATA_LEN,
	NWK_QUEUE_FULL,					// 5
	NWK_QUEUE_EMPTY,
}nwk_return_t;

typedef enum e_nwk_state_t
{
	NWK_IDLE				= 0,
	NWK_WAITING_FOR_ACK,
}nwk_state_t;

//TODO2: a lot of the functionality between nwk_tx.c and nwk_rx.c is similar, but just for the different queues, probably combine the fxns

/* ----====**** PROTOTYPES ****====---- */
nwk_packet_t* nwk_pkt_allocate(void);
bool nwk_rcv_queue_empty(void);

/* EXTERNAL API */
void nwk_init(void);
uint8_t nwk_send(uint8_t *address, uint8_t *data, uint8_t len);
uint8_t nwk_task(void);

#endif /* NWK_H_ */
